<template>
  <div class="dashboard-container">
    <div @click="$router.go(-1)">
      <i class="el-icon-back"></i>
      <span>返回</span>
    </div>
    <el-card style="height: 120px; margin-bottom: 20px">
      <!-- 给el-form绑定form -->
      <el-form label-width="80px" :model="form" :inline="true">
        <el-form-item label="日期">
          <el-date-picker
            v-model="form.dayint"
            type="date"
            style="width:203px"
            placeholder="日期筛选"
            size="default"
          />
        </el-form-item>
        <el-form-item label="关键词">
          <el-input v-model="form.title" placeholder="关键词" clearable />
        </el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          @click="searchclick"
          style="margin-left: 12px"
          >筛选</el-button
        >
        <el-button @click="resetSearch">重置</el-button>
      </el-form>
    </el-card>
    <el-table :data="tableData" border>
      <el-table-column prop="id" label="ID" align="center"> </el-table-column>
      <el-table-column prop="title" label="操作记录" align="center">
      </el-table-column>
      <el-table-column prop="dayint" label="时间" align="center">
        <template slot-scope="scope">
          {{ scope.row.dayint | datefilter }}
        </template>
      </el-table-column>

    </el-table>
    <Pagination
      :currentPage="this.form.pageNo"
      :size="this.form.pageSize"
      :total="total"
      @changelimit="changelimit"
      @changecurrentPage="changecurrentPage"
    ></Pagination>
  </div>
</template>

<script>
import { getmarketlist, delvippackagedel } from "@/api/userlog";
import { getuserlist } from '@/api/dingdan'
export default {
  name: "Dashboard",
  data() {
    return {
      form: {
        uid: "",
        dayint: "",
        title: "",
        pageNo: 1,
        pageSize: 5,
      },
      total: 0,
      tableData: [],
    };
  },
  filters: {
    datefilter(val) {
      if (val) {
        var date = new Date(parseInt(val) * 1000);
        var Year = date.getFullYear();
        var Moth =
          date.getMonth() + 1 < 10
            ? "0" + (date.getMonth() + 1)
            : date.getMonth() + 1;
        var Day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        var Hour =
          date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
        var Minute =
          date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
        var Sechond =
          date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
        var GMT = Year + "-" + Moth + "-" + Day+
          "   " +
          Hour +
          ":" +
          Minute +
          ":" +
          Sechond;

        return GMT;
      } else {
        return "";
      }
    },
  },
  methods: {
    getSimpleText(html) {
      var re1 = new RegExp("<.+?>", "g"); //匹配html标签的正则表达式，"g"是搜索匹配多个符合的内容
      var msg = html.replace(re1, ""); //执行替换成空字符
      return msg;
    },
    searchclick() {
      this.getcouponlist1();
    },
    resetSearch() {
      this.form.dayint = "";
      this.form.title = "";
      this.getcouponlist1();
    },
    addrenyuan() {
      this.$refs.add.add();
    },
    // 子传父:自定义事件
    refresh() {
      this.getcouponlist1();
    },
    async getcouponlist1() {
      // let result = await getmarketlist(this.form);
      let param={
        dayint:
          this.form.dayint == ""
            ? ""
            : Math.floor(new Date(this.form.dayint).getTime() / 1000),
      }
      let result = await getmarketlist({
        ...param,
        uid:Number(this.$route.query.uid),
        title: this.form.title,
        pageNo: this.form.pageNo,
        pageSize:this.form.pageSize,
      });


      console.log(result);
      if (result.code == 0) {
        this.tableData = result.data.data;
        this.total = result.data.totalCount;
        if (result.data.data != null) {
          result.data.data.forEach((item) => {
            if (item.status == 1) {
              this.$set(item, "switch", true);
            } else {
              this.$set(item, "switch", false);
            }
          });
        }
      }
    },
    changelimit(val) {
      this.form.pageSize = val;
      this.getcouponlist1();
    },
    changecurrentPage(val) {
      this.form.pageNo = val;
      this.getcouponlist1();
    },
    changerenyuan(val) {
      this.$refs.add.edit(val);
    },
  },
  watch: {
    "form.uid": {
      handler(newVal) {
        if (newVal == "") {
          this.getcouponlist1();
        }
      },
    },
  },
  mounted() {
    this.getcouponlist1();
  },
  // created() {
  //   this.$nextTick(() => {
  //     this.form.uid = Number(this.$route.query.uid);
  //     // 获取服务
  //     this.getservetypes1();
  //   });
  // },
};
</script>

<style lang="scss" scoped>
.dashboard {
  &-container {
    margin: 30px;
  }

  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}
</style>
